<template>
	<view>
		<u-empty mode="favor" text="暂未收藏任何商品,快去逛逛吧" iconColor="#f18b49" style="margin-top: 100rpx;" v-if="collectList == ''"></u-empty>
		<u-swipe-action style="margin: 15rpx 10rpx; 0 10rpx;" v-for="(item,index) in collectList" :key="index" v-else>
			<u-swipe-action-item autoClose :options="options" style="border-radius: 20rpx;" @click="swipeActionItem(item.id )">
				<view class="cart-list-box">
					<view class="list-box-head">
						<view class="head-left">
							<image src="../../static/cart/store.png" mode=""></image>
							<text>国集采供应链</text>
							<u-icon name="arrow-right" size="12" style="margin: 4rpx 0 0 4rpx;"></u-icon>
						</view>
						<view class="head-right">
							收藏时间：{{ item.time }}
						</view>
					</view>
					<view class="list-box-cont" @click="toProductDetail(item.goods_id)">
						<view class="listbox-cont-left">
							<image :src="baseUrl + item.img"></image>
						</view>
						<view class="listbox-cont-right">
							<view class="cont-right-top">
								<view class="cont-tit">{{ item.name }} </view>
							</view>
							<view class="cont-right-bot">
								<text class="price-icon">￥</text>
								<text class="price-tit">{{ item.sell_price }}</text>
							</view>
						</view>
					</view>
				</view>
			</u-swipe-action-item>
		</u-swipe-action>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId:'',
				collectList: [],
				options: [
					{ text: '取消收藏'}
				],
				baseUrl: 'https://gjc.hy-dzsc.cn/',
			}
		},
		onLoad(e) {
			this.userId = e.userId
		},
		onShow() {
			this.getAllCollect()
		},
		methods: {
			// 跳转商品详情
			toProductDetail(id){
				uni.navigateTo({
					url: `/pages/class/product-detail?proId=${id}&userId=${this.userId}`
				})
			},
			// 获取所有收藏商品
			getAllCollect(){
				this.collectList = []
				this.$http(`/gjcApi/getFavoriteArr?user_id=${this.userId}`, {}, res => {
					res.forEach(v => {
						this.collectList.unshift(v)
					})
				})
			},
			// 左滑取消收藏
			swipeActionItem(id){
				this.$http(`/gjcApi/delFavorite?id=${id}`, {}, res => {
					if(res.code == 200){
						this.collectList = []
						this.getAllCollect()	
						uni.showToast({
							title: '取消收藏',
							duration: 1000,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.cart-list-box{
	padding: 25rpx 20rpx;
	border-radius: 20rpx;
	background: $uni-model-color;
	.list-box-head{
		display: flex;
		align-items: center;
		justify-content: space-between;
		.head-left{
			display: flex;
			align-items: center;
			image{
				width: 36rpx;
				height: 36rpx;
				margin-right: 8rpx;
			}
			text{
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 1rpx;
			}
		}
		.head-right{
			font-size: 24rpx;
			color: $uni-text-color-grey;
		}
	}
	.list-box-cont{
		display: flex;
		margin-top: 30rpx;
		.listbox-cont-left{
			display: flex;
			align-items: center;
			image{
				// flex-shrink: 1;
				width: 200rpx;
				height: 200rpx;
				margin-left: 4rpx;
				border-radius: 10rpx;
				border: 2rpx solid $uni-text-color;
			}
		}
		.listbox-cont-right{
			width: 482rpx;
			display: flex;
			margin-left: 20rpx;
			flex-direction: column;
			justify-content: space-between;
			.cont-right-top{
				overflow:hidden;
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 1rpx;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}
			.cont-spec{
				font-size: 22rpx;
				padding: 10rpx;
				border-radius: 8rpx;
				margin: 15rpx 0 35rpx 0;
				color: $uni-text-color-grey;
				background-color:rgba(0, 0, 0, .1);
			}
			.cont-right-bot{
				display: flex;
				align-items: baseline;
				color: $uni-text-color;
				justify-content: flex-end;
				.price-icon{
					font-size: 24rpx;
				}
				.price-tit{
					font-size: 34rpx;
					font-weight: bold;
				}
			}
		}
	}
}
</style>
